package com.efast.dmom.mes.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.efast.dmom.mes.bean.QualityCheckOperation;
import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.datahandlers.entity.QualityCheckOperationHandler;
import com.efast.dmom.mes.service.QualityCheckOperationService;
@Service
public class QualityCheckOperationServiceImpl implements QualityCheckOperationService{

	@Autowired
	private QualityCheckOperationHandler qualityCheckOperationHandler;

	@Override
	public ResultBean save(QualityCheckOperation entity) {
		ResultBean resultBean = new ResultBean(true);
		List<QualityCheckOperation> byoperationAndCheck = qualityCheckOperationHandler.getByoperationAndCheck(entity);
		if (byoperationAndCheck != null && byoperationAndCheck.size()>0) {
			resultBean.setSuccess(false);
			resultBean.setMessage("当前的不良与工序关系已存在，请检查数据！");
			return resultBean;
		}
		qualityCheckOperationHandler.save(entity);
		return resultBean;
	}

	@Override
	public ResultBean delete(QualityCheckOperation entity) {
		return null;
	}

	@Override
	public ResultBean update(QualityCheckOperation entity) {
		ResultBean resultBean = new ResultBean(true);
		List<QualityCheckOperation> byoperationAndCheck = qualityCheckOperationHandler.getByoperationAndCheck(entity);
		if (byoperationAndCheck != null 
				&& byoperationAndCheck.size()>0 
				&& entity.getInnerData().getId() != byoperationAndCheck.get(0).getInnerData().getId()) {
			resultBean.setSuccess(false);
			resultBean.setMessage("当前的不良与工序关系已存在，请检查数据！");
			return resultBean;
		}
		qualityCheckOperationHandler.update(entity);
		return resultBean;
	}

	@Override
	public QualityCheckOperation getById(long id) {
		
		return null;
	}

	@Override
	public QualityCheckOperation getByName(String name) {
		
		return null;
	}

	@Override
	public ResultBean batchDeleteById(List<QualityCheckOperation> list) {
		ResultBean resultBean = new ResultBean(true);
		qualityCheckOperationHandler.batchDeleteById(list);
		return resultBean;
	}

	@Override
	public ResultBean batchDelete(List<QualityCheckOperation> list) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ResultBean save(List<QualityCheckOperation> list) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ResultBean update(List<QualityCheckOperation> list) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ResultBean delete(List<QualityCheckOperation> list) {
		// TODO Auto-generated method stub
		return null;
	}




}
